<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;

class PtGoods extends Model
{
    protected $table = 'pt_goods';		//related table name
    protected $guarded = [];

    //访问器：
    public function getPresentPriceAttribute($value)
    {
        try {
            return $value/100;
        } catch (DecryptException $e) {
            throw $e;
        }
    }


    //修改器：
    public function setPresentPriceAttribute($value)
    {
        $this->attributes['present_price']=$value*100;
    }


    //访问器：
    public function getOriginalPriceAttribute($value)
    {
        try {
            return $value/100;
        } catch (DecryptException $e) {
            throw $e;
        }
    }


    //修改器：
    public function setOriginalPriceAttribute($value)
    {
        $this->attributes['original_price']=$value*100;
    }


    //访问器：
    public function getCostPriceAttribute($value)
    {
        try {
            return $value/100;
        } catch (DecryptException $e) {
            throw $e;
        }
    }


    //修改器：
    public function setCostPriceAttribute($value)
    {
        $this->attributes['cost_price']=$value*100;
    }


    //关联到预售时间表
    public function PtPreSale()
    {
        return $this->hasMany('App\Http\Model\PtPreSale','goods_id');
    }


    //关联到素材表
    public function PtMaterial()
    {
        return $this->hasMany('App\Http\Model\PtMaterial','goods_id');
    }

    //关联供应商
    public function supps()
    {
        return $this->belongsToMany('App\Http\Model\Supp','supp_id');
    }


    //关联到规格表
    public function PtGoodsSpec()
    {
        return $this->hasMany('App\Http\Model\PtGoodsSpec','goods_id');
    }
}
